#e
#Title[䕄u-273.15x̔jv]
#Text[]
#ScriptVersion[2]

script_enemy_main {
    let imgBoss = GetCurrentScriptDirectory~".\chirno.png";

    @Initialize {
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
        SetGraphicRect(0, 0, 63, 63);
        SetLife(5000);
        SetScore(8000000);
        SetTimer(99);
        CutIn(YOUMU,"䕄u-273.15x̔jv", "", 0, 0, 0, 0);
        SetInvincibility(200);
        Tshot;

    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 24);
        SetCollisionB(GetX, GetY, 24);

        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    @Finalize {

        DeleteGraphic(imgBoss);
    }
    sub standBy {

        SetMovePosition02(228, 56, 30);
        setGraphicMove;
        loop(30){yield;}
        setGraphicStop;
        loop(70){yield;}
    }

    sub setGraphicStop  { SetGraphicRect(  0,   0, 128, 128); }
    sub setGraphicLeft  { SetGraphicRect(256,   0, 384, 128); }
    sub setGraphicRight { SetGraphicRect(256, 256, 384, 384); }

    sub setGraphicMove {
        if(GetSpeedX < 0) {
            setGraphicLeft;
        } else {
            setGraphicRight;
        }
    }

    task Tshot{
        yield;
        standBy;
        loop(100){yield;}
        let id = 1;
        let id2 = 1000000;
        let id3 = 2000000;
        loop{
            let to = GetAngleToPlayer;
            CreateShotA(id,GetX,GetY,0);
            SetShotDataA(id,0,3,to,0,0,2,BLUE03);
            SetShotDataA(id,40,0,0,0,0,0,BLUE03);
            SetShotDataA(id,50,0,0,0,0,0,WHITE03);
            let x = cos(to);
            let y = sin(to);
            loop(10){
               CreateShotA(id2,x,y,0);
               SetShotDataA(id2,0,rand(2,4),rand(to+30,to-30),0,0,2,WHITE05);
               AddShot(50,id,id2,0);
               id2 ++;
               }
            loop(10){
               CreateShotA(id2,x,y,0);
               SetShotDataA(id2,0,rand(2,4),rand(to+30,to-30),0,0,2,BLUE23);
               AddShot(50,id,id2,0);
               id2 ++;
               }
            FireShot(id);
            id ++;
            loop(25){yield;}
           if(GetEnemyLife < 2500){
           break;  
            }
          }  
        let id2 = 1000000;
        let id3 = 2000000;
        SetInvincibility(300);
        SetDamageRate(50, 0);
        loop(200){yield;}
        loop{
            let to = GetAngleToPlayer;
            CreateShotA(id,GetX,GetY,0);
            SetShotDataA(id,0,2,to,0,0,2,BLUE03);
            SetShotDataA(id,10,0,0,0,0,0,BLUE03);
            SetShotDataA(id,20,0,0,0,0,0,WHITE03);
            let x = cos(to);
            let y = sin(to);
            loop(20){
               CreateShotA(id2,x,y,0);
               SetShotDataA(id2,0,rand(2,3.2),rand(to+45,to-45),0,0,2,WHITE05);
               AddShot(20,id,id2,0);
               id2 ++;
               }
            loop(20){
               CreateShotA(id2,x,y,0);
               SetShotDataA(id2,0,rand(2,3.2),rand(to+45,to-45),0,0,2,BLUE23);
               AddShot(20,id,id2,0);
               id2 ++;
               }
            FireShot(id);
            id ++;
            loop(30){yield;}

        }   
      }

    function nway(dir, way, span, color) {

        let radius = 32;


        let angle  = dir - (way - 1) / 2 * span;

        loop(way) {

            CreateShot01(GetX, GetY, 1, angle, color, 0);
            angle += span;
        }
    }
}